package com.tle202.components;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable;

public class XImage extends Drawable {

	protected Paint m_Paint = new Paint();
	protected int m_clrBackground = Color.RED;
	protected int m_clrBorder = Color.TRANSPARENT;
	protected int m_clrX = Color.YELLOW;
	protected int m_nThick = 3;
	
	
	
	public XImage() {
		// TODO Auto-generated constructor stub
		super();
		this.setBounds(0, 0, 50, 50);
	}
	
	@Override
	public void draw(Canvas canvas) {
		// TODO Auto-generated method stub

		this.fillRect(canvas);
		this.drawX(canvas);
		this.drawBorder(canvas);
	}

	
	
	protected void fillRect (Canvas canvas) {
		
		Rect rectBound = this.getBounds();
		
		m_Paint.setStyle(Style.FILL);
		m_Paint.setColor(m_clrBackground);
		canvas.drawRect(rectBound, m_Paint);
		
		m_Paint.reset();
	}
	
	protected void drawX (Canvas canvas) {
		
		int nOffset = 1;
		Rect rectBound = new Rect(this.getBounds().left + nOffset,
				this.getBounds().top + nOffset,
				this.getBounds().right - nOffset,
				this.getBounds().bottom - nOffset);
		
		m_Paint.setStrokeCap(Cap.ROUND);
		m_Paint.setStrokeWidth(m_nThick);
		m_Paint.setStyle(Style.STROKE);
		m_Paint.setColor(m_clrX);
		canvas.drawLine(rectBound.left, rectBound.top, rectBound.right, rectBound.bottom, m_Paint);
		canvas.drawLine(rectBound.right, rectBound.top, rectBound.left, rectBound.bottom, m_Paint);
		
		m_Paint.reset();
	}
	
	protected void drawBorder (Canvas canvas) {
		
		Rect rectBound = this.getBounds();
		
		m_Paint.setStrokeWidth(m_nThick);
		m_Paint.setStyle(Style.STROKE);
		m_Paint.setColor(m_clrBorder);
		canvas.drawRect(rectBound, m_Paint);
		
		m_Paint.reset();
	}
	
	
	
	public int getBorderColor() {
		return m_clrBorder;
	}

	public void setBorderColor(int m_clrBorder) {
		this.m_clrBorder = m_clrBorder;
	}

	public int getXThick() {
		return m_nThick;
	}

	public void setXThick(int m_nThick) {
		this.m_nThick = m_nThick;
	}

	
	
	@Override
	public int getOpacity() {
		// TODO Auto-generated method stub
		return PixelFormat.OPAQUE;
	}

	@Override
	public void setAlpha(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setColorFilter(ColorFilter arg0) {
		// TODO Auto-generated method stub
	}

}
